/*
	pcr.v
	Program Counter register
	
	This project and file(s) are released under GNU GPL v3.
	Please find license file from root directory.
	Meng Sun (c) 2013 <leon.meng.sun@gmail.com>
*/

module pcr (ADDRi, CLK, nRESET, KEEP, MODE, MEMADDR);

input [19:0] ADDRi;
input CLK, nRESET, KEEP, MODE;
output [19:0] MEMADDR;

wire [19:0] ADDRi;
wire CLK, nRESET, KEEP, MODE;
reg [19:0] MEMADDR;

always @ (posedge CLK or negedge nRESET)
begin
	if (nRESET == 0) /*Async-reset*/
	begin
		MEMADDR = 20'b0;
	end else if (MODE == 0 && KEEP == 0) /*Latch ADDRi to MEMADDR*/
	begin
		MEMADDR = ADDRi;
	end else if (MODE == 1 && KEEP == 0) /*MEMADDR increase 1*/
	begin
		MEMADDR = MEMADDR + 20'b1;
	end
end

endmodule